﻿using System;
using System.Collections;
using System.Text;
using System.Configuration;
using System.Xml;

namespace YEA.Infrastructure.Gateway.Config
{
    public class AsyncReceiverCollection : ConfigurationElementCollection
    {
        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }
        protected override ConfigurationElement CreateNewElement()
        {
            return new AsyncReceiver();
        }
        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((AsyncReceiver)element).Name;
        }
        public new string AddElementName
        {
            get { return base.AddElementName; }
            set { base.AddElementName = value; }
        }
        public new string ClearElementName
        {
            get { return base.ClearElementName; }
            set { base.ClearElementName = value; }

        }

        public new string RemoveElementName
        {
            get { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }


        public AsyncReceiver this[int index]
        {
            get
            {
                return (AsyncReceiver)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public AsyncReceiver this[string Name]
        {
            get { return (AsyncReceiver)BaseGet(Name); }
        }

        public int IndexOf(AsyncReceiver asyncReceiver)
        {
            return BaseIndexOf(asyncReceiver);
        }

        public void Add(AsyncReceiver asyncReceiver)
        {
            BaseAdd(asyncReceiver);
            // Add custom code here.
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
            // Add custom code here.
        }

        public void Remove(AsyncReceiver asyncReceiver)
        {
            if (BaseIndexOf(asyncReceiver) >= 0)
                BaseRemove(asyncReceiver.Name);
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
            // Add custom code here.
        }
    }
}
